package czy.demo.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.util.Date;

/**
 * 实体类，使用Entity注解，会被自动扫描
 * 如果需要会根据实体类生成数据库表
 * 注意这里的注解value为Person类映射到的名称，并非表名
 * 表名使用Table注解设置，这里的value在HQL查询语句中使用
 */
@ApiModel("Person实体模型")
@Entity(name = "Person")
public class Person {

    @Id
    @ApiModelProperty("主键ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /* 字符串长度默认为255 */
    @ApiModelProperty("名称")
    @Column(length = 50,nullable = false,unique = true)
    private String name;

    @ApiModelProperty("年龄")
    @Column(nullable = false)
    private Integer age;

    /**
     *  java类型Date对应的数据库类型为DATETIME
     *  而且Column注解没有指定类型的字段，只能columnDefinition指定sql片段
     */
    @ApiModelProperty("创建日期")
    @Column(columnDefinition = "TIMESTAMP(3)",nullable = false)
    private Date birthday;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }
}
